package com.zhonghui.controller;

import com.zhonghui.common.core.result.FwResult;
import com.zhonghui.dto.CartAddDto;
import com.zhonghui.dto.CartUpdateDto;
import com.zhonghui.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Delegate;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 购物车-控制层
 * @author: FL
 * @create: 2024 2024/5/11 14:51
 */
@RestController
@Api(value = "购物车控制层")
@Slf4j
@Validated
public class CartController {
    @Autowired
    private CartService cartService;

    @ApiOperation("购物车列表")
    @GetMapping("/cart/list")
    public FwResult getCartList() {
        return cartService.getCartList();
    }

    @ApiOperation("新增购物车")
    @PostMapping("/cart/add")
    public FwResult addCart(@RequestBody CartAddDto cartAddDto) {
        return cartService.addCart(cartAddDto);
    }

    @ApiOperation("更新购物车")
    @PutMapping("/cart")
    public FwResult updateCart(@RequestBody CartUpdateDto cartUpdateDto) {
        return cartService.updateCart(cartUpdateDto);
    }

    @ApiOperation("删除购物车")
    @DeleteMapping("/cart/{id}")
    public FwResult deleteCart(@PathVariable Long id) {
        return cartService.deleteCart(id);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/cart/clear")
    public FwResult getCartCount() {
        return cartService.clearCart();
    }
}
